Because Deck.gl is one of the most user-friendly WebGL javascript libraries and can produce some beautiful maps. And it integrates nicely with Mapbox maps.
Simply calling mapdeck() gives you a map
You can style the map using any mapbox style template styles, or you can create one of your own
key <- "pk.eyJ1Ijoic3ltYm9saXgiLCJhIjoiY2pqbm45Zmo1MGl1aTNxbmxwamFqb3Z6MSJ9.yIkj0tGNNh4u61DliOXV6g"
url <- 'https://raw.githubusercontent.com/plotly/datasets/master/2011_february_aa_flight_paths.csv'
flights <- read.csv(url)
flights$id <- seq_len(nrow(flights))
flights$stroke <- sample(1:3, size = nrow(flights), replace = T)
mapdeck( token = key, style = 'mapbox://styles/mapbox/dark-v9', pitch = 45 ) %>%
add_arc(
data = flights
, layer_id = "arc_layer"
, origin = c("start_lon", "start_lat")
, destination = c("end_lon", "end_lat")
, stroke_from = "airport1"
, stroke_to = "airport2"
, stroke_width = "stroke"
)key <- "pk.eyJ1Ijoic3ltYm9saXgiLCJhIjoiY2pqbm45Zmo1MGl1aTNxbmxwamFqb3Z6MSJ9.yIkj0tGNNh4u61DliOXV6g"
mapdeck( token = key, style = 'mapbox://styles/mapbox/dark-v9', pitch = 45 ) %>%
add_scatterplot(
data = capitals
, lat = "lat"
, lon = "lon"
, radius = 100000
, fill_colour = "country"
, layer_id = "scatter_layer"
)Currently only encoded polylines are supported.
key <- "pk.eyJ1Ijoic3ltYm9saXgiLCJhIjoiY2pqbm45Zmo1MGl1aTNxbmxwamFqb3Z6MSJ9.yIkj0tGNNh4u61DliOXV6g"
mapdeck(
token = key
, style = 'mapbox://styles/mapbox/dark-v9'
, location = c(145.688269, -38.101062)
, zoom = 8) %>%
add_path(
data = roads
, polyline = "geometry"
, stroke_colour = "RIGHT_LOC"
, layer_id = "path_layer"
)library(sf)
# Linking to GEOS 3.6.1, GDAL 2.1.3, proj.4 4.9.3
library(geojsonsf)
sf <- geojson_sf("https://symbolixau.github.io/data/geojson/SA2_2016_VIC.json")
mapdeck(
token = key
, style = 'mapbox://styles/mapbox/dark-v9'
) %>%
add_polygon(
data = sf
, layer = "polygon_layer"
, fill_colour = "SA2_NAME16"
)
df1 <- capitals[ capitals$country == "Australia", ]
df2 <- capitals[ capitals$country != "Australia", ]
df1$key <- 1
df2$key <- 1
df <- merge(df1, df2, by = 'key')
mapdeck(
token = key
, style = 'mapbox://styles/mapbox/dark-v9'
, pitch = 35
) %>%
add_arc(
data = df
, origin = c("lon.x", "lat.x")
, destination = c("lon.y", "lat.y")
, layer_id = "arc_layer"
, stroke_from = "country.x"
, stroke_to = "country.y"
, stroke_width = 2
) %>%
add_scatterplot(
data = df2
, lon = "lon"
, lat = "lat"
, radius = 100000
, fill_colour = "country"
, layer_id = "scatter"
)watch this space!
It works… but need to figure out data updates and update triggers…